import { request } from '@/utils/request';
// 知识库列表相关的接口
/**
 * 知识库下文档的目录树返回接口
 */
const getKnowledgeBaseDirectoryByUserId = ()=>{
    const userId = localStorage.getItem('userId');
    return request({
        url:`/knowledgeBase/getKnowledgeBaseDirectoryByUserId/${userId}`,
        method:"GET"
    }) 
}
/**
 * 根据用户id查询该用户所拥有的知识库
 * @returns {Promise<ApiRet>}
 */
const searchKnowledgeBaseList =()=>{
    const userId = localStorage.getItem('userId');
    return request({
        url: `/knowledgeBase/getKnowledgeBaseList/${userId}`,
        method: "GET"
    })
}

/**
 * 编辑知识库
 * @param {string} knowledgeBaseId 知识库id
 * @param {string} name 知识库名称
 * @param {string} description 知识库描述
 * @param {string} owner 知识库所属用户id
 */
const editKnowledgeBaseMessage = ({ knowledgeBaseId, name, description, owner } = {}) => {
    return request({
        url: '/knowledgeBase/editKnowledgeBaseMessage',
        method: "POST",
        data: {
            knowledgeBaseId,
            name,
            description,
            owner,
        }
    })
}

/**
 * 根据知识库id删除知识库
 * @param {string} knowledgeBaseId 知识库id
 */

const deleteKnowledgeBase = ({knowledgeBaseId})=>{
    const params = {
        knowledgeBaseId
    }
    return request({
        url: '/knowledgeBase/deleteKnowledgeBase',
        method: "POST",
        params
    })
}

/**
 * 根据知识库名称查询知识库
 * @param {string} name 知识库名称
 */
const searchKnowledgeBaseByName = ({name})=>{
    const params = {
        name
    }
    return request({
        url: '/knowledgeBase/searchKnowledgeBase',
        method: "GET",
        params
    })
}

/**
 * 新建知识库
 * @param {string} name 知识库名称
 * @param {string} description 知识库描述
 * @param {string} owner 知识库所属用户id
 */

const createKnowledgeBase = ({ name, description, owner }) => {
    return request({
        url: '/knowledgeBase/insertKnowledgeBase',
        method: "POST",
        data: {
            name,
            description,
            owner
        }
    });
};

/**
 * 根据知识库id查询该知识库下的所有文档列表
 * @param {string} knowledgeBaseId 知识库id
 */

const getDocListOfKnowledgeBase = ({knowledgeBaseId})=>{
    const params = {
        knowledgeBaseId
    }
    return request({
        url:'/knowledgeBase/getDocListOfKnowledgeBase',
        method: "GET",
        params
    })
}
    export { 
    editKnowledgeBaseMessage,
    searchKnowledgeBaseList,
    deleteKnowledgeBase,
    searchKnowledgeBaseByName,
    createKnowledgeBase,
    getDocListOfKnowledgeBase,
    getKnowledgeBaseDirectoryByUserId
}